<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
	request.setAttribute("path", request.getContextPath());
%>
<script type="text/javascript">
$(function(){
	common.ajaxQuery("${root}/app/code/item/list");

	$("#id").change(function (){
		var val = $.trim($(this).val());
			if(common.isNotEmpty(val) && common.isNotNumberic(val)){
				$(this).val("");
				common.modalGlobalMessage("编码只能输入数字!");
			}
	});
});
function newCodeItem(){
	
	common.moalYesNoDialog(getTemplate(),"编码详细","saveItem('','#new_seq','#new_name','#new_extension')");
}
function getTemplate(){

	var html = '<div id="new_template"><div class="control-group">' +
	    '<label for="name" class="control-label">顺序:</label>' +
	    '<div class="controls">' +
			'<input type="text" class="form-control" name="seq" maxlength="3" id="new_seq" />' +
	    '</div></div><div class="control-group">' +
	    '<label for="name" class="control-label">名称:</label>' +
	    '<div class="controls">' +
			'<input type="text" class="form-control" name="name" maxlength="50" id="new_name" />' +
	    '</div></div><div class="control-group">' +
	    '<label for="name" class="control-label">备注:</label>' +
	    '<div class="controls">' +
			'<input type="text" class="form-control" name="extension" maxlength="50" id="new_extension" />' +
		'</div></div></div>' ;
 	return html;
	
}
function saveItem(id,seq,name,extension){
	
	var seqVal = $.trim($(seq).val());
	if(common.isEmpty(seqVal) || common.isNotNumberic(seqVal)){
		alert("请输入数字类型的编码顺序!");
		return;
	}
	var val = $.trim($(name).val());
	if(common.isEmpty(val)){
		alert("请输入编码名称!");
		return;
	}
	 var param={};
	 if(id){
		 param.id = $(id).val();
	 }
	 param.appCodeId = $("#appCodeId").val();
	 param.seq = $(seq).val();
	 param.name = $(name).val();

	 var extension = $.trim($(extension).val());
	 param.extension = extension;
	 var uri = "${root}/app/code/item/update"
	 common.ajaxSubmitWithData(uri,param,"保存编码失败","",'updateSucc()');
	 
}
function updateSucc(){
	common.closeYesNoDialog();
	common.ajaxQuery("${root}/app/code/item/list");
}
function modifyItem(index){
	$("#sequence"+index).removeAttr("disabled");
	$("#name"+index).removeAttr("disabled");
	$("#extension"+index).removeAttr("disabled");
	$("#save"+index).removeClass("hide");
	$("#modify"+index).addClass("hide");
	
	return false;
}
function delCode(codeId){
	if(confirm("确定删除此系统编码!")){
		var url = "${root}/app/code/item/delete/" + codeId;
		common.ajaxSubmit( url ,"","删除系统编码失败,请重试!","",'common.ajaxQuery("${root}/app/code/item/list")');
	}
}
</script>
<form class="form-horizontal" id="queryForm" role="form">
	<input name="orderName" value="sequence" type="hidden">
	<input id="appCodeId" name="appCodeId" value="${param.appCodeId}" type="hidden">
	<table class="table table-hover">
		<tr>
			<th class="span3 text-right">编码:</th>
			<td>&nbsp;<input type="text" class="input-xlarge" name="id" id="id" /></td>
			<th  class="span3 text-right">名称:</th>
			<td>&nbsp;<input type="text" class="input-xlarge" name="name" id="name" /></td>
		</tr>
		<tr>
		</tr>
	</table>
	<div class="form-actions text-center">
			    <button type="button" class="btn btn-primary" onclick="common.ajaxQuery('${root}/app/code/item/list')">查询</button>
		      <button type="button" class="btn btn-success" onclick="newCodeItem()">新增</button>
	 </div>
</form>
<h4 class="text-danger" style="text-indent: 10px">${param.appCodeName } 设置</h4>
<div class="table-responsive">
<table class="table table-striped table-bordered">
	<thead>
		<tr >
			<th class="span2 text-center">序号</th>
			<th class="span2 text-center">类别</th>
			<th class="span2 text-center">顺序</th>
			<th class=" text-center">名称</th>
			<th class="span3 text-center">备注</th>
			<th class="span3 text-center">操作</th>
		</tr>
	</thead>
	<tbody id="dataList">
	</tbody>
</table>
</div>



